	
import useFunction from "./useFunction";
import { reactive, ComponentPublicInstance } from "vue";


/** 工具函数 */
const toolFunction = useFunction();


/** 计算词汇高度 */
const useWordHeight = (options: { proxy: ComponentPublicInstance, viewSelector: string, translationSelector: string }) => {
	const { proxy, viewSelector = '.items-word', translationSelector = '.items-word .hidden-block-translation' } = options || {};
	
	return {
		/** 获取节点 */
		get: async (callback: (value: { viewHeight: number, translationHeight: number }) => void) => {
			const view = await toolFunction.getRect(viewSelector, proxy);
			const translation = await toolFunction.getRect(translationSelector, proxy);
			const result = reactive({
				viewHeight: view.height,
				translationHeight: translation.height,
			});
			
			callback?.(result);
			return result;
		},
		
		/** 计算高度 */
		calculatedHeight: <T>(value: T, viewHeight: number, translationHeight: number) => {
			return value ? viewHeight + translationHeight : viewHeight;
		}
	}
};


export default useWordHeight;